<template>
	<view class="flex flex-direction align-center justify-center" style="width: 100%;height: 100vh;">
		<image style="width: 50vw" src="../../static/logo.png" mode="widthFix"></image>
		<text class="margin-top text-bold text-xl">微信授权中...</text>
	</view>
</template>

<script>
	//#ifdef H5
	var jweixin = require('jweixin-module')
	//#endif
	export default {
		data() {
			return {
				urlData: '',
				userInfo: this.$helper.userInfo,
				loginUser: {
					loginName: "xia",
					password: "root123",
					loginType: "NAME_PASSWORD"
				},
				CustomBar: this.CustomBar,
			}
		},
		onLoad(data) {
			console.log("onload:", data);
			if (data.equipmentNo || data.msgType) {
				this.urlData = '?' +
					(data.equipmentNo ? 'equipmentNo=' + data.equipmentNo + '&' : '') +
					(data.msgType ? 'msgType=' + data.msgType : '');
				console.log("this.urldata:", this.urlData);
			}
			let tenantId = this.$helper.tenantId;
			if (data.tenantId) {
				tenantId = data.tenantId;
			}
			//#ifdef H5
			this.authorizeUrl(tenantId);
			//#endif
		},
		onShow() {
			// this.userlogin();

		},
		methods: {
			authorizeUrl(tenantId) {
				var that = this;
				var url = window.location.href.split('#')[0];
				let comitData = {
					"loginName": "",
					"loginResultUrl": url + "#/pages/login/index" + that.urlData,
					// "loginResultUrl": url+"#/pages/login/index?equipmentNo=1002323&msgType=1",
					"loginType": "WECHAT_ENTERPRISE_WEB",
					"scanGoal": "1",
					tenantId
				};
				that.$api.authorizeUrl(comitData).then(res => {
					console.log("authorizeUrl==============", res);
					if (res.code == 0) {
						uni.setStorageSync('authorize_url', res.data)
						setTimeout(() => {
							window.location.href = res.data
						}, 500)
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none',

							duration: 3000
						});
					}
				}).catch(error => {
					console.log(error);
				})
			}
		},
	}
</script>

<style>
</style>